/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.manage.core.service;

import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceInvoke;
import info.peigen.hotpot.manage.core.service.facade.RelationServiceFacade;
import info.peigen.hotpot.manage.core.service.order.RelationCreateOrder;
import info.peigen.hotpot.manage.core.service.order.RelationEditOrder;
import info.peigen.hotpot.manage.core.service.result.RelationCreateResult;
import info.peigen.hotpot.manage.core.service.result.RelationEditResult;
import org.noear.solon.annotation.Component;

/**
 * <b>(RelationService)</b>
 * "关联关系" 服务实现
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2024-06-28
 */
@SuppressWarnings({"unused", "rawtypes"})
@Component
public class RelationService extends AbstractHotpotManageService implements RelationServiceFacade {

    @Override
    public RelationCreateResult create(RelationCreateOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new RelationCreateResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(relationCreateProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(relationStoreProcessor, relationCreateResultProcessor);
            }
        });
        return (RelationCreateResult) serviceContext.getResult();
    }

    @Override
    public RelationEditResult edit(RelationEditOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new RelationEditResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addPreProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(relationActiveProcessor);
            }

            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(relationEditProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(relationStoreProcessor, relationEditResultProcessor);
            }
        });
        return (RelationEditResult) serviceContext.getResult();
    }
}